\documentclass[a4paper,draft,oneside]{report}

\reversemarginpar

\usepackage{mathptmx}
\usepackage{a4wide}
\usepackage{xcolor}
\usepackage[italian]{babel}
\usepackage{amsmath}
\usepackage{stmaryrd}
\usepackage{mathpartir}
\usepackage{calrsfs}

\newcommand{\NT}[1]{\langle\mathit{#1}\rangle}
\newcommand{\T}[1]{\mathit{#1}}

\newcommand{\flang}{$\mathcal{F}$}
\newcommand{\olang}{$\mathcal{O}$}
\newcommand{\cflang}{$\mathcal{F}^{+}$}
\newcommand{\colang}{$\mathcal{O}^{+}$}

\newcommand{\INT}{\T{int}}
\newcommand{\BOOL}{\T{bool}}
\newcommand{\FLOAT}{\T{float}}
\newcommand{\STRING}{\T{string}}
\newcommand{\SYMBOL}{\T{symbol}}

\newcommand{\EXPR}{E}
\newcommand{\VAL}{v}
\newcommand{\VARVAL}{w}
\newcommand{\VAR}{x}
\newcommand{\REF}{r}
\newcommand{\RULE}{\NT{rule}}
\newcommand{\CONST}{k}
\newcommand{\PATTERN}{\NT{pattern}}
\newcommand{\BIND}{\NT{bind}}
\newcommand{\GLOBAL}{\NT{global}}
\newcommand{\PRIM}[1]{\mathit{op}^{(#1)}}

\newcommand{\CLASS}{\mathit{CL}}
\newcommand{\CLASSID}{\mathsf{C}}
\newcommand{\VARCLASSID}{\mathsf{D}}
\newcommand{\FIELDID}{\mathsf{f}}
\newcommand{\VARFIELDID}{\mathsf{g}}
\newcommand{\METHODID}{\mathsf{m}}
\newcommand{\OBJECTID}{\mathsf{o}}
\newcommand{\VAROBJECTID}{\mathsf{p}}
\newcommand{\FIELD}{\NT{field}}
\newcommand{\HEAP}{h}
\newcommand{\CTOR}{K}
\newcommand{\METHOD}{M}
\newcommand{\nil}{\mathtt{nil}}
\newcommand{\CLOSUREID}[1]{\mathtt{Closure}\langle#1\rangle}
\newcommand{\PAPID}[2]{\mathtt{PAP}\langle#1,#2\rangle}
\newcommand{\APPLY}[1]{\mathtt{apply}\langle#1\rangle}
\newcommand{\VALUE}{\mathtt{Value}}
\newcommand{\MAXARGS}{M}

\newcommand{\INSTR}[1]{\mathsf{#1}}
\newcommand{\TRUE}{\mathsf{true}}
\newcommand{\FALSE}{\mathsf{false}}
\newcommand{\THIS}{\mathtt{this}}

\newcommand{\BOXN}[1]{[]_{#1}}
\newcommand{\BOX}[1]{[#1]}
\newcommand{\ENV}{\mathcal{E}}
\newcommand{\LOC}{\mathcal{L}}
\newcommand{\ARGS}{\mathcal{A}}

\newcommand{\TRANS}{\Rightarrow}
\newcommand{\AFTER}{\vdash}

\newcommand{\kfix}[1]{\mathtt{fix}_{#1}~\VAR_1=\VAL_1\cdots\VAR_n=\VAL_n}
\newcommand{\varkfix}[1]{\mathtt{fix}_{#1}~\sequence{\VAR}=\sequence{\VAL}}

\newcommand{\sequence}[1]{\overline{#1}}
\newcommand{\seqlen}[1]{\#(#1)}

\newcommand{\EVAL}[1]{\mathcal{E}[#1]}
\newcommand{\COMPILE}[3]{\llbracket\,#1\,\rrbracket^{#2}_{#3}}

\newcommand{\rtsyntax}[1]{\colorbox{lightgray}{\ensuremath{#1}}}
\newcommand{\subst}[2]{
	\{ 	\raisebox{.5ex}{$#1$}  /  
			\raisebox{-.5ex}{$#2$} \} 
	} % substitution
\newcommand{\subt}{\mathrel{<:}}
\newcommand{\fields}{\mathit{fields}}
\newcommand{\CT}{\mathit{CT}}
\newcommand{\body}{\mathit{body}}
\newcommand{\dom}{\mathrm{dom}}
\newcommand{\rulename}[1]{\textsc{(#1)}}
\newcommand{\fv}{\mathit{fv}}

\newtheorem{extension}{Estensione}

\title{Implementazione orientata a oggetti puri \\ di un linguaggio funzionale}

\begin{document}

\maketitle

\chapter{Introduzione}

\chapter{perch\'e oggetti}

\section{Il linguaggio \flang}

La sintassi del linguaggio funzionale {\flang} \`e mostrata in
Tabella~\ref{tab:fsyntax} e utilizza un insieme di \emph{variabili}
denotate da $x$, $y$, \dots. La sintassi consta di due categorie
sintattiche, $\VAL$ per i \emph{valori} e $\EXPR$ per le
\emph{espressioni}. Usiamo la notazione $\sequence{X}$ per denotare
una sequenza non vuota $X_1,\dots,X_n$ di valori/espressioni.
%
Una espressione atomica pu\`o essere un valore $v$ o una variabile
$x$.
%
L'espressione $\EXPR~\EXPR_1\cdots\EXPR_n$ denota l'applicazione della
funzione $\EXPR$ agli argomenti $\EXPR_1\cdots\EXPR_n$.
%
L'espressione $\kfix{k}$ denota la definizione di $n$ funzioni
mutuamente ricorsive, ciascuna con nome $\VAR_i$. L'intera espressione
\`e equivalente alla $k$-esima funzione definita, ovvero a $\VAL_k$.

Per quanto riguarda i valori, il termine
$\mathtt{fun}~\VAR_1\cdots\VAR_n \to \EXPR$ denota una funzione a $n$
argomenti $x_1,\dots,x_n$ il cui corpo \`e l'espressione $\EXPR$.
%
Il termine
$\mathtt{pap}~(\mathtt{fun}~\VAR_1\cdots\VAR_n\to\EXPR)~\VAL_1\cdots\VAL_m$
denota l'applicazione parziale della funzione
$\mathtt{fun}~\VAR_1\cdots\VAR_n\to\EXPR$ agli argomenti
$\VAL_1,\dots,\VAL_m$. In quanto parziale, deve essere $n > m$, ovvero
la funzione accetta pi\`u argomenti di quelli effettivamente
forniti. Il fatto che i termine rappresentanti applicazioni parziali
sono evidenziato con $\rtsyntax{\text{sfondo grigio}}$ sta a indicare
che tali termini possono comparire solo durante la valutazione di una
espressione del linguaggio {\flang}. Pertanto, tali termini \emph{non}
compaiono nei programmi scritti dal programmatore.

\begin{table}
\caption{\label{tab:fsyntax} Sintassi del linguaggio~\flang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{rcl@{\qquad}l}
\VAL & ::= & \mathtt{fun}~\sequence{\VAR}\to\EXPR \\
  & | & \rtsyntax{\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL}} & \seqlen{\sequence{\VAR}} > \seqlen{\sequence{\VAL}} \\
\\
\EXPR & ::= & \VAL \\
  & | & \VAR \\
  & | & \EXPR~\sequence{\EXPR} & \\
  & | & \varkfix{k} & 1 \le k \le \seqlen{\sequence{\VAR}} \\
\end{array}
\end{math}
}
\end{table}

\begin{table}
\caption{\label{tab:feval} Valutazione delle espressioni del linguaggio \flang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{@{}c@{}}
\inferrule[\rulename{E-Sat}]{
  \seqlen{\sequence{\VAR}} = \seqlen{\sequence{\VAL}}
}{
  {(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL}}
  \to
  {\EXPR\subst{\sequence{\VAL}}{\sequence{\VAR}}}
}
\qquad
\inferrule[\rulename{E-SatApp}]{
  \seqlen{\sequence{\VAR}} = \seqlen{\sequence{\VAL}}
}{
  {(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL},\sequence{\VARVAL}}
  \to
  {\EXPR\subst{\sequence{\VAL}}{\sequence{\VAR}}~\sequence{\VARVAL}}
}
\qquad
\inferrule[\rulename{E-Pap}]{
  \seqlen{\sequence{\VAR}} > \seqlen{\sequence{\VAL}}
}{
  {(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL}}
  \to
  {\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL}}
}
\\\\
\inferrule[\rulename{E-PapSat}]{
  \seqlen{\sequence{\VAR}} = \seqlen{\sequence{\VAL},\sequence{\VARVAL}}
}{
  {(\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL})~\sequence{\VARVAL}}
  \to
  {\EXPR\subst{\sequence{\VAL},\sequence{\VARVAL}}{\sequence{\VAR}}}
}
\qquad
\inferrule[\rulename{E-PapSatApp}]{
  \seqlen{\sequence{\VAR}} = \seqlen{\sequence{\VAL},\sequence{\VARVAL}}
}{
  {(\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL})~\sequence{\VARVAL},\sequence{\VARVAL}'}
  \to
  {\EXPR\subst{\sequence{\VAL},\sequence{\VARVAL}}{\sequence{\VAR}}~\sequence{\VARVAL}'}
}
\\\\
\inferrule[\rulename{E-PapPap}]{
  \seqlen{\sequence{\VAR}} > \seqlen{\sequence{\VAL},\sequence{\VARVAL}}
}{
  {(\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL})~\sequence{\VARVAL}}
  \to
  {\mathtt{pap}~(\mathtt{fun}~\sequence{\VAR}\to\EXPR)~\sequence{\VAL},\sequence{\VARVAL}}
}
\\\\
\inferrule[\rulename{E-Fix}]{}{
  {\varkfix{k}}
  \to
  {\VAL_k\subst{\varkfix{1}}{x_1}}\cdots\subst{\varkfix{n}}{x_n}
}
% \\\\
% \inferrule{
%   \VARVAL_i = \VAL_i\subst{\mathtt{let}~\mathtt{rec}~\VAR_1=\VAL_1\cdots\VAR_n=\VAL_n~\mathtt{in}~\VAR_j}{\VAR_j}^{j=1..n}
% }{
%   {\mathtt{let}~\mathtt{rec}~\VAR_1=\VAL_1\cdots\VAR_n=\VAL_n~\mathtt{in}~\EXPR}
%   \to
%   {\EXPR\subst{\VARVAL_i}{\VAR_i}^{i=1..n}}
% }
\qquad
\inferrule[\rulename{E-Context}]{
  \EXPR \to \EXPR'
}{
  \EVAL{\EXPR} \to \EVAL{\EXPR'}
}
\end{array}
\end{math}
}
\end{table}

Con $\EVAL{\EXPR}$ denotiamo una generica espressione in cui occorre
$\EXPR$. Siccome il calcolo \`e confluente non dobbiamo preoccuparci
dell'ordine di valutazione.

\section{Il linguaggio \olang}

\begin{table}
\caption{\label{tab:osyntax} Sintassi del linguaggio \olang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{rcl@{\qquad}l}
\CLASS & ::= & \mathtt{class}~\CLASSID~\mathtt{extends}~\CLASSID~\{
  \sequence{\FIELDID};
  ~\CTOR
  ~\sequence{\METHOD}
  \} \\
\\
\CTOR & ::= & \CLASSID(\sequence{\FIELDID})
  ~\{\THIS.\sequence{\FIELDID}=\sequence{\FIELDID};\} \\
\\
\METHOD & ::= & \METHODID(\sequence{\VAR})~\{\EXPR\} \\
\\
\EXPR & ::= & \REF \\
& | & \EXPR.\FIELDID \\
& | & \EXPR.\METHODID(\sequence{\EXPR}) \\
& | & \mathtt{new}_k~\sequence{\REF} = \sequence{\CLASSID(\sequence{\EXPR})} & 1 \le k \le \seqlen{\sequence{\REF}} \\
\\
\REF & ::= & \VAR \mid \rtsyntax{\OBJECTID \mid \nil} \\
\end{array}
\end{math}
}
\end{table}

\begin{table}
\caption{\label{tab:fields}\strut Campi di una classe.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{@{}c@{}}
  \inferrule{}{
    \fields(\mathtt{Object}) = {\bullet}
  }
  \qquad
  \inferrule{
    \CT(\CLASSID) = \mathtt{class}~\CLASSID~\mathtt{extends}~\VARCLASSID~\{
    \sequence{\FIELDID};
    ~
    \CTOR
    ~
    \sequence{\METHOD}
    \}
    \\
    \fields(\VARCLASSID) = \sequence{\VARFIELDID}
  }{
    \fields(\CLASSID) = \sequence{\VARFIELDID},\sequence{\FIELDID}
  }
\end{array}
\end{math}
}
\end{table}

\begin{table}
\caption{\label{tab:methods}\strut Risoluzione di metodo.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{@{}c@{}}
  \inferrule{
    \CT(\CLASSID) = \mathtt{class}~\CLASSID~\mathtt{extends}~\VARCLASSID~\{
    \sequence{\FIELDID};
    ~
    \CTOR
    ~
    \sequence{\METHOD}
    \}
    \\
    \METHODID(\sequence{x})~\{\EXPR\} \in \sequence{\METHOD}
  }{
    \body(\METHODID, \CLASSID) = (\sequence{x}, \EXPR)
  }
  \\\\
  \inferrule{
    \CT(\CLASSID) = \mathtt{class}~\CLASSID~\mathtt{extends}~\VARCLASSID~\{
    \sequence{\FIELDID};
    ~
    \CTOR
    ~
    \sequence{\METHOD}
    \}
    \\
    \text{$\METHODID$ non definito in $\sequence{\METHOD}$}
  }{
    \body(\METHODID, \CLASSID) = \body(\METHODID, \VARCLASSID)
  }
\end{array}
\end{math}
}
\end{table}

\begin{table}
\caption{\label{tab:obj-eval}\strut Valutazione delle espressioni del linguaggio \olang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{@{}c@{}}
  \inferrule[\rulename{E-Field}]{
    \HEAP(\OBJECTID) = \CLASSID(\sequence{\VAROBJECTID})
    \\
    \fields(\CLASSID) = \sequence{\FIELDID}
  }{
    \EVAL{\OBJECTID.\FIELDID_i}, \HEAP
    \to
    \EVAL{\VAROBJECTID_i}, \HEAP
  }
  \qquad
  \inferrule[\rulename{E-Method}]{
    \HEAP(\OBJECTID) = \CLASSID(\sequence{\VAROBJECTID})
    \\
    \body(\METHODID, \CLASSID) = (\sequence{\VAR},\EXPR)
  }{
    \EVAL{\OBJECTID.\METHODID(\sequence{\OBJECTID})},
    \HEAP
    \to
    \EVAL{\EXPR\subst{\sequence{\OBJECTID}}{\sequence{\VAR}}\subst{\OBJECTID}{\THIS}},
    \HEAP
  }
  % \qquad
  % \inferrule[\rulename{E-Let}]{}{
  %   \EVAL{\mathtt{let}~\sequence{\VAR}=\sequence{\OBJECTID}~\mathtt{in}~\EXPR},
  %   \HEAP
  %   \to
  %   \EVAL{\EXPR\subst{\sequence{\OBJECTID}}{\sequence{\VAR}}},
  %   \HEAP
  % }
  \\\\
  \inferrule[\rulename{E-Alloc}]{
    \OBJECTID_i \not\in \dom(\HEAP)
  }{
    \EVAL{\mathtt{new}_k~\sequence{\VAR} = \sequence{\CLASSID(\sequence{\EXPR})}},
    \HEAP
    \to
    \EVAL{\mathtt{new}_k~\sequence{\OBJECTID} = \sequence{\CLASSID(\sequence{\EXPR}\subst{\sequence{\OBJECTID}}{\sequence{\VAR}})}},
    \HEAP[\sequence{\OBJECTID} \mapsto \sequence{\CLASSID(\sequence{\nil})}]
  }
  \\\\
  \inferrule[\rulename{E-Init}]{}{
    \EVAL{\mathtt{new}_k~\sequence{\OBJECTID}=\sequence{\CLASSID(\sequence{\VAROBJECTID})}},
    \HEAP[\sequence{\OBJECTID} \mapsto \sequence{\CLASSID(\sequence{\nil})}]
    \to
    \EVAL{\OBJECTID_k},
    \HEAP[\sequence{\OBJECTID} \mapsto \sequence{\CLASSID(\sequence{\VAROBJECTID})}]
  }
\end{array}
\end{math}
}
\end{table}

\section{Il compilatore}

\begin{table}
\caption{\label{tab:runtime}\strut Definizione delle classi $\CLOSUREID{m}$ e $\PAPID{m}{n}$.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{@{}l@{\quad}l@{}}
  \mathtt{class}~\CLOSUREID{m}~\mathtt{extends}~\mathtt{Object}~\{
  & 1 \le m \le \MAXARGS 
  \\
  \quad \CLOSUREID{m}()~\{
  ~\} \\
  \quad \APPLY{\seqlen{\sequence{x}}}(\sequence{x})~\{~
  \mathtt{new}_1~\mathit{pap}=\PAPID{m}{\seqlen{\sequence{x}}}(\mathtt{this},\sequence{x})
  ~\}
  & 1 \le \seqlen{\sequence{x}} < m \\
  \quad \APPLY{\seqlen{\sequence{x},\sequence{y}}}(\sequence{x},\sequence{y})~\{~
  \mathtt{this}.\APPLY{m}(\sequence{x}).\APPLY{\seqlen{\sequence{y}}}(\sequence{y})
  ~\}
  & m = \seqlen{\sequence{x}} < \seqlen{\sequence{x},\sequence{y}} \le \MAXARGS \\
  \}
  \\\\
  \mathtt{class}~\PAPID{m}{n}~\mathtt{extends}~\mathtt{Object}~\{
  & 1 \le n < m \le \MAXARGS
  \\
  \quad \mathit{cls}, \sequence{\VAL};
  & n = \seqlen{\sequence{\VAL}} \\
  \quad \PAPID{m}{n}(\mathit{cls},\sequence{\VAL})~\{~
  \mathtt{this}.\mathit{cls},\sequence{\VAL} = \mathit{cls},\sequence{\VAL};
  ~\} \\
  \quad \APPLY{\seqlen{\sequence{x}}}(\sequence{x})~\{~
  \mathtt{new}_1~\mathit{pap}=\PAPID{m}{n + \seqlen{\sequence{x}}}(\mathtt{this}.\mathit{cls},\mathtt{this}.\sequence{\VAL},\sequence{x})
  ~\}
  & 1 \le \seqlen{\sequence{x}} < m - n
  \\
  \quad \APPLY{\seqlen{\sequence{x}}}(\sequence{x})~\{~
  \mathtt{this}.\mathit{cls}.\APPLY{m}(\mathtt{this}.\sequence{\VAL},\sequence{x})
  ~\}
  & m - n = \seqlen{\sequence{x}}
  \\
  \quad \APPLY{\seqlen{\sequence{x},\sequence{y}}}(\sequence{x},\sequence{y})~\{~
  \mathtt{this}.\mathit{cls}.\APPLY{m}(\mathtt{this}.\sequence{\VAL},\sequence{x}).\APPLY{\seqlen{\sequence{y}}}(\sequence{y})
  ~\}
  & m - n = \seqlen{\sequence{x}} < \seqlen{\sequence{x},\sequence{y}} \le \MAXARGS \\
  \} 
\end{array}
\end{math}
}
\end{table}

\begin{table}
\caption{\label{tab:comp}\strut Compilazione del linguaggio {\flang} nel linguaggio {\olang}.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{rcl}
  \COMPILE{x}{\sequence{y}}f & = &
  \begin{cases}
    x & x \in \sequence{y} \\
    \THIS & x = f \\
    \THIS.x & \text{altrimenti} 
  \end{cases}
  \\
  \COMPILE{\mathtt{fun}~\sequence{x} \to \EXPR}{\sequence{y}}{f} & = &
  \mathtt{new}_1 {?} = \CLASSID(\COMPILE{\sequence{z}}{\sequence{y}}{f}) \\
  \text{dove}
  & &
  \sequence{z} = \fv(\EXPR) \setminus \sequence{x} \\
  & & 
  \mathtt{class}~\CLASSID~\mathtt{extends}~\CLOSUREID{\seqlen{\sequence{x}}}~\{ \\
  & & \quad \sequence{z}; \\
  & & \quad \CLASSID(\sequence{z})~\{ \THIS.\sequence{z} = \sequence{z}; \} \\
  & & \quad \APPLY{\seqlen{\sequence{x}}}(\sequence{x})~\{ \COMPILE{\EXPR}{\sequence{x}}{{?}} \} \\
  & & \}
  \\
  \COMPILE{\EXPR~\sequence{\EXPR}}{\sequence{y}}{f} & = &
  \COMPILE{\EXPR}{\sequence{y}}{f}.\APPLY{\seqlen{\sequence{\EXPR}}}(\COMPILE{\sequence{\EXPR}}{\sequence{y}}{f})
  \\
  \COMPILE{\mathtt{fix}_k~\sequence{f}=\sequence{\mathtt{fun}~\sequence{x}\to\EXPR}}{\sequence{y}}{f} & = & 
  \mathtt{new}_k~\sequence{f}=\sequence{\CLASSID(\COMPILE{\sequence{z}}{\sequence{y}}{f})}
  \\
  \text{dove}
  & &
  \sequence{z}_i = \fv(\EXPR_i) \setminus f_i,\sequence{x}_i \\
  & & \mathtt{class}~\CLASSID_i~\mathtt{extends}~\CLOSUREID{\seqlen{\sequence{x}_i}}~\{ \\
  & & \quad \sequence{z}_i; \\
  & & \quad \CLASSID_i(\sequence{z}_i)~\{ \THIS.\sequence{z}_i = \sequence{z}_i; \} \\
  & & \quad \APPLY{\seqlen{\sequence{x}_i}}(\sequence{x}_i)~\{ \COMPILE{\EXPR_i}{\sequence{x}_i}{{f_i}} \} \\
  & & \}
\end{array}
\end{math}
}
\end{table}

\chapter{Prototipo}

\section{Il linguaggio \cflang}

\begin{table}
\caption{\label{tab:cfsyntax} Sintassi del linguaggio~\cflang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{rcl@{\qquad}l}
\EXPR & ::= & \CONST \\
  & | & \VAR \\
  & | & \mathtt{fun}~\sequence{\VAR}\to\EXPR \\
  & | & \EXPR~\sequence{\EXPR} & \\
  & | & \PRIM{n}~\sequence{\EXPR} & \seqlen{\sequence{\EXPR}} = n \\
  & | & \mathtt{let}~[\mathtt{rec}]~\sequence{x} = \sequence{\EXPR}~\mathtt{in}~\EXPR \\
  & | & \mathtt{if}~\EXPR~\mathtt{then}~\EXPR~\mathtt{else}~\EXPR \\
\end{array}
\end{math}
}
\end{table}

\section{Il linguaggio \colang}

\begin{table}
\caption{\label{tab:cosyntax} Sintassi del linguaggio \colang.}
\framebox[\textwidth]{
\begin{math}
\displaystyle
\begin{array}{rcl@{\qquad}l}
\CLASS & ::= & \mathtt{class}~\CLASSID~\mathtt{extends}~\CLASSID~\{
  \sequence{\CLASSID}~\sequence{\FIELDID};
  ~\CTOR
  ~\sequence{\METHOD}
  \} \\
\\
\CTOR & ::= & \CLASSID(\sequence{\CLASSID}~\sequence{\FIELDID})
  ~\{\THIS.\sequence{\FIELDID}=\sequence{\FIELDID};\} \\
\\
\METHOD & ::= & \CLASSID~\METHODID(\sequence{\CLASSID}~\sequence{\VAR})~\{\EXPR\} \\
\\
\EXPR & ::= & \CONST \\
& | & \VAR \\
& | & (\CLASSID)\EXPR \\
& | & \EXPR.\FIELDID \\
& | & \EXPR.\METHODID(\sequence{\EXPR}) \\
& | & \PRIM{n}~\sequence{\EXPR} & \seqlen{\sequence{\EXPR}} = n \\
& | & \mathtt{let}~\sequence{\VAR} = \sequence{\EXPR}~\mathtt{in}~\EXPR & \seqlen{\sequence{\VAR}} > 0 \\
& | & \mathtt{new}~\sequence{\VAR} = \sequence{\CLASSID(\sequence{\EXPR})}~\mathtt{in}~\EXPR & \seqlen{\sequence{\VAR}} > 0 \\
  & | & \mathtt{if}~\EXPR~\mathtt{then}~\EXPR~\mathtt{else}~\EXPR \\
\end{array}
\end{math}
}
\end{table}


\chapter{Conclusioni}

\end{document}



